<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>循环注册</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" type="text/css" th:href="@{/js/layui/css/layui.css}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/cba/style.css/}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/cba/my.css/}" media="all">
    <style>
        .childrenBody{
            padding: 30px;
        }
    </style>
</head>
<body class="childrenBody">
<button type="button" class="layui-btn" id="test1" style="margin-bottom: 20px;">
    <i class="layui-icon">&#xe67c;</i>导入注册
</button>

<form class="layui-form html_save" lay-filter="form">
    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-block">
            <input class="layui-input" name="phone" lay-verify="number|required" placeholder="从该手机号开始循环注册" type="number">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">数量</label>
        <div class="layui-input-block">
            <input class="layui-input" name="count" lay-verify="number|required" placeholder="请输入循环注册数量" type="number">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">是否互为好友</label>
        <div class="layui-input-block">
            <input type="checkbox" name="isFriend"  lay-skin="switch" lay-text="好友|非好友" id="isFriend">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">是否加入群</label>
        <div class="layui-input-block">
            <input class="layui-input-inline" type="checkbox" name="isNewGroup" lay-filter="isNewGroup" lay-skin="switch"
                   lay-text="加入|不加入" id="isNewGroup">
            <input class="layui-input-inline layui-input" name="groupId" id="groupId" style="width: 300px"
                   placeholder="指定加入的群ID，确保群Id存在" type="number">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">上级邀请码</label>
        <div class="layui-input-block">
            <input class="layui-input" name="recommendCode" lay-verify="recommendCode" placeholder="请输入上级邀请码" type="text">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">登录密码</label>
        <div class="layui-input-block">
            <input class="layui-input" name="password" lay-verify="username|required" placeholder="请输入登录密码" type="text">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">支付密码</label>
        <div class="layui-input-block">
            <input class="layui-input" name="payPassword" lay-verify="number|required" placeholder="请输入支付密码" type="text">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveContainer">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<div class="layui-form-item">
    <label class="layui-form-label">注册结果</label>
    <div class="layui-input-block">
        <textarea placeholder="注册结果将在这里显示" class="layui-textarea" id="resultMsg"></textarea>
    </div>
</div>

<script th:src="@{/js/layui/layui.js}"></script>
<script th:src="@{/js/cba/login-timeout.js}"></script>
<!--<script type="text/javascript" src="js/newsadd.js"></script>-->

<script type="text/javascript" th:inline="javascript">
    layui.use(['upload', 'form', "layer"], function () {
        var form = layui.form
            , upload = layui.upload
            , layer = layui.layer
            , $ = layui.jquery;

        $("#groupId").hide();

        var registerAuto = [[${registerAuto}]];
        if (registerAuto != null) {
            form.val("form", {
                "password": registerAuto.password // "name": "value"
                , "phone": registerAuto.phone
            });
        }

        var uploadInst = upload.render({
            elem: '#test1', //绑定元素
            accept:'file',
            url: [[${basePath}]] + '/register/importExcel'
            ,before: function(obj){
                var loadingIndex = layer.load (1, {shade: [0.5, '#000']});
            }
            , done: function (res) {
                layer.closeAll ('loading');
                layer.msg("导入成功！");

            }
            , error: function () {
                //请求异常回调
                layer.closeAll ('loading');
            }
        });

        form.on('switch(isNewGroup)', function(data){
            if (data.elem.checked) {
                $("#groupId").show();
            } else {
                $("#groupId").hide();
            }
        });

        form.on('submit(saveContainer)', function (data) {
            data.field.isFriend = data.field.isFriend === "on";
            data.field.isNewGroup = data.field.isNewGroup === "on";
            var loading = layer.load();
            $.ajax({
                url: [[${basePath}]] + "/registerAuto/save", data: data.field, type: "post", success: function (data) {
                    if (data.success) {
                        if (data.data != null) {
                            $("#resultMsg").val(data.data);
                        } else {
                            $("#resultMsg").val("null");
                        }
                        layer.msg(data.msg, {icon: 1});
                        setTimeout(function () {
                            parent.layer.close();
                        }, 1000);
                    } else {
                        $("#resultMsg").val(data.msg);
                        layer.msg(data.msg, {icon: 5});
                    }
                }, complete: function () {
                    layer.close(loading);
                }
            });

            return false;
        });

    });
</script>
</body>
</html>